package com.chat.api.web.dao;

import com.chat.api.common.BaseRepo;
import com.chat.api.web.po.BlogBean;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BlogRepo extends BaseRepo<BlogBean,Long> {
    @Query(value = "select * from blog where status = '通过' ORDER BY create_date desc limit ?1,5",nativeQuery = true)
    List<BlogBean> findAllByLimit(Integer pageNum);

    @Query(value = "select * from blog where id=?1",nativeQuery = true)
    BlogBean findOneById(Long id);

    @Query(value = "select * from blog where status = '通过' ORDER BY views desc limit 0,5",nativeQuery = true)
    List<BlogBean> findHotInfo();

    @Query(value = "select * from blog where status = '通过' and create_date > (select create_date from blog where id = ?1) order by create_date asc limit 1",nativeQuery = true)
    BlogBean findLastInfo(Long id);

    @Query(value = "select * from blog where status = '通过' and create_date < (select create_date from blog where id = ?1) order by create_date desc limit 1",nativeQuery = true)
    BlogBean findNextInfo(Long id);

    @Query(value = "select SUM(a.views) views from (select * from blog where status = '通过' ORDER BY views desc limit 5,1000) a",nativeQuery = true)
    Integer findReadOther();

    @Query(value = "select * from blog ",nativeQuery = true)
    List<BlogBean> findApprovalList();

    @Query(value = "select * from blog where user_id = ?1",nativeQuery = true)
    List<BlogBean> findListByUserId(Long id);

    @Query(value = "select * from blog where title = ?1 and status = '通过'",nativeQuery = true)
    BlogBean selectByTitleAndStatus(String title);

    @Query(value = "select * from blog where title = ?1 ",nativeQuery = true)
    BlogBean selectByTitle(String title);
}
